package cn.itcast.com.Thread.ver2;

public class Container {
    public synchronized void setFood(Food newfood) throws InterruptedException {
        if (food != null){
            this.wait();
        }else {
            this.food = newfood;
            System.out.println(Thread.currentThread().getName()+ "做了"+ newfood);
            //this.food = newfood;
            this.notify();
        }
    }
    public synchronized void eatFodd() throws InterruptedException {
        if (food == null){
            this.wait();
        }else {
            System.out.println(Thread.currentThread().getName()+"吃了"+food);
            food = null;
            this.notifyAll();
        }
    }
    //让当前的使用者知道当前蒸笼是否有包子
    public boolean isEmpty(){
        return food == null;
    }

    private Food food;
}
class Food{

    private String name;

    private double price;

    public Food(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Food{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}